<?php

namespace app\admin\model;

use think\Model;

class WithdrawModel extends Model
{
    // 确定链接表名
    protected $name = 'withdraw';
    
    public function getStatusAttr($value){
        $status = ['未处理', '已处理'];
        return $status[$value];
    }

    /**
     * 根据搜索条件获取订单列表信息
     * @param $where
     * @param $offset
     * @param $limit
     */
    public function getUsersByWhere($where, $offset, $limit)
    {
        return $this->where($where)->limit($offset, $limit)->order('id desc')->select();
    }

    /**
     * 根据搜索条件获取所有的订单数量
     * @param $where
     */
    public function getAllUsers($where)
    {
        return $this->where($where)->count();
    }

    /**
     * 改变当前状态到下一状态
     */
    public function updateStatus($orderid){
        try {
            $this->where('id', $orderid)->update(['status'=>1]);
            return msg(1, '', 'ok');
        } catch (\Throwable $th) {
            //throw $th;
            return msg(-1, '', $th->getMessage());
        }
    }
}
